#ifndef TALKWINDOW_H
#define TALKWINDOW_H

#include <QWidget>

namespace Ui {
    class TalkWindow;
}
#include "talkwindow/emotion/EmotionWindow.h"

#include <data/File.pb.h>
#include <data/Message.pb.h>
#include <data/UserInfo.pb.h>
#include <packge/packge.h>
using namespace proto;

// #include <packet/Packet.h>
// #include <packet/file/FilePacket.h>
#include <set>
// #include <packet/message/Message.h>
#include <module/basicwindows.h>
#include <queue>


class TalkWindow : public QWidget {
    Q_OBJECT

private:
    Ui::TalkWindow*    ui;
    EmotionWindow*     emotionWindow;
    QString            userId;
    data::FriendInfo     userInfo;
    data::ChatRoomInfo roomInfo;
    bool               isMessageWebViewLoadFinishd = false;
    enum TALCK_TYPE {
        PTOP,
        GROUP
    } type = TALCK_TYPE::PTOP;

public:
    explicit TalkWindow(QWidget* parent = nullptr);
    ~TalkWindow();

public:
    void setTitle(QString title);
    // void setUserId(QString userid);
    void setInfo(const data::FriendInfo& userInfo);
    void setInfo(const data::ChatRoomInfo& roomInfo);

private:
    void init();
    void initEmotionWindow();
    void initMessageWebView();

    void onWebViewLoadFinishd();

    void onButtonCloseClicked();
    void onButtonMaxClicked();
    void onButtonMinClicked();
    void onButtonRestoreClicked();

signals:
    void signalButtonCloseClicked();
    void signalButtonMaxClicked();
    void signalButtonMinClicked();
    void signalButtonRestoreClicked();
    void signalNewMessage(std::shared_ptr<::proto::data::Message> msg);

public slots:
    void onWindowRestore();
    void onNewMessage(std::shared_ptr<::proto::data::Message> msg);
    void onEmotionItemClicked(int emotionNum);

    // void onUploadFile(packet::file::FileInfo info, int code, QString message);

    // void uploadFile(QString path);

    void onSendButtonClicked();
    void onFileopenBtnClicked();
    void onImgopenBtnClicked();
    void onUploadFileSchedule(QString fileName, size_t fileSize, size_t schedule);

private:
    QString parseHtml(const QString& htmlText);
    // template <typename T>
    // void sendPacket(T& pack) {
    //     Application::sendPacket(pack);
    // }
    std::vector<std::shared_ptr<::proto::data::Message>> messages;
    std::queue<QString>                                    m_talk_files;
    std::set<QString>                                      m_uploeadFiles;
};

#endif  // TALKWINDOW_H
